package org.dromara.app.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.bean.domain.HisRegistration;
import org.dromara.bean.domain.bo.HisRegistrationBo;
import org.dromara.bean.domain.vo.HisRegistrationVo;
import org.dromara.bean.service.IHisRegistrationService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 挂号
 *
 * @author Lion Li
 * @date 2024-11-30
 */
@Validated
@SaIgnore
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/registration")
public class AHisRegistrationController extends BaseController {

    private final IHisRegistrationService hisRegistrationService;



    /**
     * 查询挂号记录列表
     */
    @GetMapping("/list")
    public TableDataInfo<HisRegistrationVo> list(HisRegistrationBo bo, PageQuery pageQuery) {

        return hisRegistrationService.xcxQueryPageList(bo, pageQuery);
    }


    /**
     * 获取挂号记录详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<HisRegistrationVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(hisRegistrationService.xcxQueryById(id));
    }

    /**
     * 新增挂号记录
     */
    @Log(title = "挂号记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<HisRegistration> add(@Validated(AddGroup.class) @RequestBody HisRegistrationBo bo) {
        return R.ok(hisRegistrationService.insertByBo(bo));
    }

    /**
     * 支付
     */
    @GetMapping("/pay")
    public  R<?>  pay( String orderNo) {
        return hisRegistrationService.pay(  orderNo, "2");
    }

    /**
     * 取消挂号
     */
    @GetMapping("/cancel")
    public  R<?>  cancel(HisRegistrationBo bo) {
        return R.ok(hisRegistrationService.cancel(bo));
    }

    /**
     * 申请退款
     */
    @PutMapping()
    public R<?> update(@RequestBody HisRegistration hisRegistration)  {
        return hisRegistrationService.update(hisRegistration);
    }

}
